/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.esisar.picaso.ihm;

import fr.esisar.picaso.entites.Livre;
import fr.esisar.picaso.requetes.RequetesStatistiques;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author THOMAS
 */
public class FenetreInterneStatistiques extends javax.swing.JInternalFrame {

    /**
     * Creates new form FenetreInterneStatistiques
     */
    public FenetreInterneStatistiques() {
        initComponents();
        getStats();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setClosable(true);
        setIconifiable(true);
        setTitle("Statistiques");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null}
            },
            new String [] {
                "Nombre de commandes", "Prix moyen des commandes", "Recettes totales", "Client le plus rentable"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 651, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

    private void getStats() {
        RequetesStatistiques r = new RequetesStatistiques();
        try {
            int nbCommandes = r.nombreCommandes();
            float prixMoyen = r.prixMoyenCommandes();
            float recettes = r.recettes();
            String meilleurClient = r.meilleurClient();
            //ArrayList<Livre> tousCommandes = r.livresCommandesParTous();
            
            jTable1.setValueAt(nbCommandes, 0, 0);
            jTable1.setValueAt(prixMoyen, 0, 1);
            jTable1.setValueAt(recettes, 0, 2);
            jTable1.setValueAt(meilleurClient, 0, 3);
        } catch (SQLException ex) {
            Logger.getLogger(FenetreInterneStatistiques.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
